<%--
  Created by IntelliJ IDEA.
  User: zhao
  Date: 6/11/2022
  Time: 15:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" >

</head>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-3.6.1.min.js"></script>
<body>
<form class="layui-form" action="" id="changePassword" >
    <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-inline">
            <input type="password" name="usedpass" id="usedpass" required lay-verify="required" placeholder="请输入原密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="pass" id="pass" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required|pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="tijiao">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-3.6.1.min.js"></script>
<script>
    //Demo
        layui.use(['form','layer','jquery'], function(){
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery;
            var upload = layui.upload
                , element = layui.element;

            // // 自定义校验  验证两次密码是不是一样
            form.verify({
                pass: function(value){ //自定义lay-verify的昵称，value：表单的值
                    var pass1 = $("#pass").val();
                    if(value!=pass1){
                        return "两次密码不一致！！！";
                    }

                }
            });
            //提交
            form.on('submit(tijiao)', function(data){
                // alert(JSON.stringify(data.field))
                var usedpass = data.field.usedpass;
                $.ajax({
                    url:"${pageContext.request.contextPath}/tuser/usedpass",
                    type:"post",
                    dataType:"JSON",
                    data:data.field,//表单里所有数据
                    success:function (res) {
                        if (res.data==true) {
                            // layer.msg("修改成功",{icon:"1"});
                            // var index=parent.layer.getFrameIndex(window.name);
                            <%--window.location="${pageContext.request.contextPath}/views/login.jsp"--%>
                            // alert(JSON.stringify(data.field))
                            $.ajax({
                                 url:"${pageContext.request.contextPath}/tuser/updPassword",
                                 type:"post",
                                 dataType:"JSON",
                                 data:data.field,//表单里所有数据
                                 success:function (res) {
                                     // alert(JSON.stringify(res))
                                     if (res.data==true) {
                                         alert("修改成功")
                                         layer.msg("修改成功");
                                         $("#changePassword")[0].reset();

                                         // var index=parent.layer.getFrameIndex(window.name);
                                         <%--window.location="${pageContext.request.contextPath}/views/login.jsp"--%>
                                     }else {
                                         layer.msg("修改失败");
                                         $("#changePassword")[0].reset();

                                     }
                                 }
                             });



                        }else {
                            alert("原密码错误")
                            layer.msg("原密码错误");
                            $("#changePassword")[0].reset();
                        }
                    }
                });

            });




        });


</script>

</html>
